namespace hjc {

	export class MediatorManager extends Singleton implements ILaunchable {

		private $mediators: Mediator[] = [];

		public add(...mediators: Mediator[]): void {
			this.$mediators.push(...mediators);
		}

		public launch(options: LaunchOptions): void {
			if (notEmptyArr(options.Mediators))
				options.Mediators.unique().forEach((clazz: new () => Mediator) => this.$mediators.push(new clazz()));
		}

		public get<M extends Mediator>(clazz: new () => M): M {
			for (let mediator of this.$mediators) {
				if (mediator instanceof clazz) return mediator;
			}
			let mediator = new clazz();
			this.$mediators.push(mediator);
			return mediator;
		}

		public getAll(): Mediator[] { return this.$mediators; }
	}
}